﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.EarTagCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.API.Controllers;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.EarTagHandler
{
    public class EarTagAddCommandHandler : IRequestHandler<EarTagAddCommand, Results<int>>
    {
        private readonly IEarTagService _earTagService;
        private readonly IMapper _mapper;

        public EarTagAddCommandHandler(IEarTagService earTagService, IMapper mapper)
        {
            _earTagService = earTagService;
            _mapper = mapper;
        }
        /// <summary>
        /// 添加耳标
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(EarTagAddCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<EarTagTable>(request);
            return Results<int>.DataResult(await _earTagService.AddEarTags(result));
        }
    }
}
